package com.leve.control.mapper;

import com.leve.control.domain.DeviceCat;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author whongyu
 * @create by 2019/7/1
 */
@Repository
public interface DeviceCatMapper {

    @Insert(" insert into ims_levepower_iot_device_cat(`device_id`, `iot_device_id`, `iot_device_secret`)values( #{deviceId}, #{iotDeviceId}, #{iotDeviceSecret}) ")
    int add(DeviceCat deviceCat);

    @Select(" select `id`,`device_id`,`iot_device_id`,`iot_device_secret` from ims_levepower_iot_device_cat where id = #{device_id} ")
    DeviceCat getDeviceCatByDeviceId(String deviceId);

    @Update("<script>" +
            "update ims_levepower_iot_device_cat " +
            "<set>" +
            "<if test=\"deviceId != null\">`device_id` = #{deviceId}, </if>" +
            "<if test=\"iotDeviceId != null\">`iot_device_id` = #{iotDeviceId}, </if>" +
            "<if test=\"iotDeviceSecret != null\">`iot_device_secret` = #{iotDeviceSecret} </if>" +
            "</set>" +
            " where id = #{id}" +
            "</script>")
    int update(DeviceCat deviceCat);
}
